{{define "title"}}
	{{with .Content}}{{.Doc.Title}}{{else}}Error{{end}}
{{end}}

{{define "head"}}
	{{if (or (not .Content) .ContentVersion)}}<meta name="robots" content="noindex">{{end}}
{{end}}

{{define "content"}}
	{{with .Content}}
		<nav id="index">
			{{if .Doc.Title}}{{template "index" .}}{{end}}
		</nav>
	{{end}}
	<section id="content">
		{{with .Content}}
			<nav id="breadcrumbs" class="breadcrumbs">
				{{range $index, $e := .Breadcrumbs}}
					<a href="{{$e.URL}}" class="{{if $e.IsActive}}active{{end}}">
						{{- if eq $index 0 -}}
							Home
						{{- else -}}
							{{$e.Label}}
						{{- end -}}
					</a> {{if not $e.IsActive}}/{{end}}
				{{end}}
			</nav>
			<div class="markdown-body">{{markdown .}}</div>
		{{else}}
			{{if .ContentVersionNotFoundError}}
				<h1>Version not found</h1>
                <p>The version <code>{{.ContentVersion}}</code> was not found.</p>
                <p>
                    <a href="javascript:window.location.assign(`/{{.ContentPagePath}}${window.location.hash}`)">Click here</a>
                    to view the latest version of this page instead.
                </p>
			{{else if .ContentPageNotFoundError}}
				<h1>Page not found</h1>
				<p>The page <code>{{.ContentPagePath}}</code> was not found.</p>
			{{else}}<h1>Unexpected error</h1>
			{{end}}
		{{end}}
	</section>
{{end}}

{{define "index"}}
	{{with (or (and (eq (len .Doc.Tree) 1) (index .Doc.Tree 0).Children) .Doc.Tree)}}
		<h4>{{$.Doc.Title}}</h4>
		<p class="on-this-page">On this page:</p>
		<ul>{{template "doc_nav" .}}</ul>
	{{end}}
    <a class="page-btn" href="https://github.com/sourcegraph/sourcegraph/edit/main/doc/{{.FilePath}}">Edit this page</a>
{{end}}
{{define "doc_nav"}}
	{{range .}}
		<li>
			<a href="{{.URL}}">{{.Title}}</a>
			{{with .Children}}
				<ul>
					{{template "doc_nav" .}}
				</ul>
			{{end}}
	{{end}}
{{end}}
